package edu.rpi.cs.webgraph.graphfragment;

import edu.uci.ics.jung.algorithms.scoring.PageRank;
import edu.uci.ics.jung.graph.Graph;

import java.util.Collection;
import java.util.Map;

/**
 * Author: josh
* Date: Apr 12, 2009
* Time: 5:34:51 PM
*/
public class GraphWrapper<N, E> {
    private static final double DAMPING_FACTOR = 0.85;

    private PageRank<N, E> pageRank = null;
    private final Graph<N, E> wrappedGraph;

    public GraphWrapper(final Graph<N, E> graph) {
        wrappedGraph = graph;
    }

    public Collection<N> getNodes() {
        return null;
    }

    public Map<N, Collection<N>> getInEdges() {
        return null;
    }

    public Map<N, Collection<N>> getOutEdges() {
        return null;
    }

    public boolean areAdjacent(final N first,
                               final N second) {
        return false;
    }
    
    public double getPageRankForNode(final N node) {
        // TODO: synchronize if necessary
        if (null == pageRank) {
            pageRank = new PageRank<N, E>(wrappedGraph, 1 - DAMPING_FACTOR);
            pageRank.evaluate();
        }
        
        return pageRank.getVertexScore(node);
    }
}
